home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000013_icon-group-sender _Mon Jul 24 09:07:26 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA07485
for icon-group-addresses; Mon, 24 Jul 2000 09:07:17 -0700 (MST)
Message-Id: <200007241607.JAA07485@baskerville.CS.Arizona.EDU>
Date: Mon, 24 Jul 2000 08:24:06 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: Todd Nathan <todd@palomablanca.net>,
icon-group <icon-group@optima.CS.Arizona.EDU>
Subject: Re: deep write()?
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 2276
Todd Nathan wrote:
>
> Is there a deep write method.
>
> Just come came across what I suspect there to be a weakness
> inherent in the function write(). No knowing how to do repeated
> recursive diggin, how would someone write a deep write...
>
> The following fails.
>
> procedure main ()
>
> car1 := ["buick", "skylark", 1978, 2450]
> car2 := ["bmw", "535is", 1987, 3000]
>
> inventory := [car1, car2]
>
> write (inventory)
>
> end
When write() encounters an argument that can't be converted to
type string, it uses the image() function to display it. What
you're really asking for is a "deep" image() function.
Because Icon structures can contain *anything* including
references to themselves, a deep image is non-trivial, though
possible.
Consider, for example, what the output should be if the
above line:
inventory := [car1, car2]
were followed by
put(inventory, inventory)
(perfectly legal code, if meaningless in this context...)
What should the deep image (and hence write()) produce?
A general purpose deep image has got to be able to handle the above.
It's probably simpler to write a special-purpose one yourself
if you are *absolutely* certain your structures are not cyclic graphs.
> I would like to see the 'write (inventory)' work as a deep
> write....
Well, here's one to deep write a list, assuming the list is
acyclic. (Handling a cyclic structure is left as an exercise... :)
procedure deepWrite(args[])
outfile := &output
every arg := !args do {
case type(arg) of {
"file": outfile := arg
default: writes(outfile, deepImage(arg))
}
}
write(outfile)
end
procedure deepImage(arg)
local resultString
if string(arg) then return string(arg)
case type(arg) of {
"list": {
resultString := "["
every resultString ||:= deepImage(!arg) || ","
resultString[-1] := "]" # change last , to ]
return resultString
}
default: return image(arg) # cop out on other structures
}
end
Note that this code *depends* on any list passed to deepImage as being
acyclic - it *won't* work on cyclic structures!
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu